﻿@model sBlog.Net.Areas.Admin.Models.PostViewModel
<script src="@Url.Content("~/Content/ckeditor/ckeditor.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#PublicDate").datepicker(
        {
            changeMonth: true,
            changeYear: true,
            yearRange: '-1:+10',
            dateFormat: 'yy-mm-dd',
            showAnim: 'slideDown'
        });
    });
</script>
<script type="text/javascript">
    $(window).load(
    function () {
        $("#dvUpload").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': 'Min 660x380',
            'script': '@Url.Action("UploadAvatar")',
            'onComplete': function (event, queueID, fileObj, response, data) {
                var res = response.split("/");
                var imgName = res[res.length - 1];
                imgName = imgName.split("_");

                $("#FolderImage").val(res[res.length - 2]);

                $("#PostAvatar").val(imgName[imgName.length - 1]);
                var imgUrl = response;
                $("#imgAvatar").attr("src", imgUrl).fadeIn('normal');
            },
            'folder': '/Admin/Post/UploadAvatar',
            'sizeLimit': '1048576',
            'fileDesc': '.jpg Files',
            'fileExt': '*.jpg',
            'multi': true,
            'auto': true
        });

        $("#dvUploadAvatarFeasture").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': '990 x 392',
            'script': '@Url.Action("UploadAvatarFeature")',
            'onComplete': function (event, queueID, fileObj, response, data) {
                var res = response.split("/");
                var imgName = res[res.length - 1];
                imgName = imgName.split("_");
                $("#PostAvatarFeature").val(imgName[imgName.length - 1]);
                var imgUrl = response;
                $("#imgAvatarFeature").attr("src", imgUrl).fadeIn('normal');
            },
            'folder': '/UploadThumbs',
            'sizeLimit': '1048576',
            'fileDesc': '.jpg Files',
            'fileExt': '*.jpg',
            'multi': true,
            'auto': true
        });

        $("#dvUploadAvatarSquare").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': '196 x 196',
            'script': '@Url.Action("UploadAvatarSquare")',
            'onComplete': function (event, queueID, fileObj, response, data) {
                var res = response.split("/");
                var imgName = res[res.length - 1];
                imgName = imgName.split("_");
                $("#PostAvatarSquare").val(imgName[imgName.length - 1]);
                var imgUrl = response;
                $("#imgAvatarSquare").attr("src", imgUrl).fadeIn('normal');
            },
            'folder': '/UploadThumbs',
            'sizeLimit': '1048576',
            'fileDesc': '.jpg Files',
            'fileExt': '*.jpg',
            'multi': true,
            'auto': true
        });

        $("#dvUploadAvatarYanNews").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': '550 x 275',
            'script': '@Url.Action("UploadAvatarYanNews")',
            'onComplete': function (event, queueID, fileObj, response, data) {
                var res = response.split("/");
                var imgName = res[res.length - 1];
                imgName = imgName.split("_");
                $("#PostAvatarYanNews").val(imgName[imgName.length - 1]);
                var imgUrl = response;
                $("#imgAvatarYanNews").attr("src", imgUrl).fadeIn('normal');
            },
            'folder': '/UploadThumbs',
            'sizeLimit': '1048576',
            'fileDesc': '.jpg Files',
            'fileExt': '*.jpg',
            'multi': true,
            'auto': true
        });

        $("#divContentUploader").fileUpload({
            'uploader': '/Scripts/uploader.swf',
            'cancelImg': '/Content/Images/cancel.png',
            'buttonText': 'Insert image',
            'script': '@Url.Action("UploadImageContent")',
            'onComplete': function (event, queueID, fileObj, response, data) {
                var html = "<div><img src='" + response + "' /></div>";
                InsertHTML(html);
            },
            'folder': '/UploadImageContent',
            'sizeLimit': '1048576',
            //'fileDesc': '.jpg Files',
            //'fileExt': '*.jpg',
            'multi': true,
            'auto': true
        });
    }
);
</script>
<script type="text/javascript">
    $(document).ready(function () {
        CKEDITOR.replace('Post_PostContent');
    });

    function InsertHTML(htmlText) {
        var oEditor = CKEDITOR.instances.Post_PostContent;

        var newElement = CKEDITOR.dom.element.createFromHtml(htmlText, oEditor.document);
        oEditor.insertElement(newElement);
    }

</script>
<script type="text/javascript">
    function ValidForm() {
        var str = $("#PostAvatar").val();
        if (str == '') {
            alert('Bạn phải chọn hình');
            $("#PostAvatar").focus();
            return false;
        }
        return true;
    }
</script>
<script type="text/javascript">+
    $(document).ready(function () {
        $("#Post_ZoneId").change(function () {
            var url = '@Url.Content("~/")' + "Post/CatType_SelectedState";
            var ddlsource = "#Post_ZoneId";
            var ddltarget = "#Post_CatId";
            $.getJSON(url, { id: $(ddlsource).val() }, function (data) {
                $(ddltarget).empty();
                $.each(data, function (index, optionData) {
                    $(ddltarget).append("<option value='" + optionData.Value + "'>" + optionData.Text + "</option>");
                });
            });
        });
    });
</script>
@using (Html.BeginForm())
{
    <div id="maincontent">
        <div id="left" style="float: left; width: 72%; padding: 15px;">
            @Html.Partial("UpdatePostOrPageStatus", Model)
            <div style="clear: both;">
            </div>
            <br />
            <br />
            @Html.HiddenFor(model => model.Post.PostID)
            @Html.HiddenFor(model => model.Post.PostAddedDate)
            @Html.HiddenFor(model => model.Post.Status)
            @{
    var display = "Post";
    if (Model.Post.EntryType == 2)
    {
        display = "Page";
    }
            }
            <div class="editor-label">
                Chuyên mục
            </div>
            <div class="editor-field">
                @Html.DropDownList("Post.ZoneId", (SelectList)ViewBag.lstZone, new { style = "width: 150px" })
            </div>
            <div class="editor-label">
                Chuyên mục con
            </div>
            <div class="editor-field">
                @Html.DropDownList("Post.CatId", (SelectList)ViewBag.lstCateZone, new { style = "width: 150px" })
            </div>
            <b>Tiêu đề</b><br />
            @Html.TextBoxFor(model => model.Post.PostTitle, new { @class = "inputBoxBigPost postTitle" })
            <br />
            <br />
            <b>Trích dẫn</b><br />
            @Html.TextAreaFor(model => model.Post.PostDescription, new { rows = 6, cols = 76 })
            <br />
            <br />
            @{
    string folder = string.Empty;
    if (int.Parse(Model.Post.PostYear + Model.Post.PostMonth) <= 201405)
    {
        folder = "201405";
    }
    else
    {
        folder = Model.Post.PostYear + Model.Post.PostMonth;
    }
            }
            @if (Roles.IsUserInRole("SuperAdmin") || Roles.IsUserInRole("Admin"))
            {   
                <img id="imgAvatarFeature" src="@Url.Content("http://s1.img.yan.vn/Mlog/UploadThumbs/" + folder + "/" + ViewData["PostAvatarFeature"])" alt=""/>
                <br />
                <div>
                    <div style="float: left; margin-top: 10px; margin-right: 43px;">
                        <b>@Html.Raw("Tiêu điểm")</b>
                    </div>
                    <div id="dvUploadAvatarFeasture">
                        @Html.Hidden("PostAvatarFeature", ViewData["PostAvatarFeature"])
                    </div>
                </div>
                <br />
                <img id="imgAvatarSquare" src="@Url.Content("http://s1.img.yan.vn/Mlog/UploadThumbs/" + folder + "/196x196_" + ViewData["PostAvatarSquare"])" alt=""/>
                <br />
                <div>
                    <div style="float: left; margin-top: 10px; margin-right: 10px;">
                        <b>@Html.Raw("Hình size vuông")</b>
                    </div>
                    <div id="dvUploadAvatarSquare">
                        @Html.Hidden("PostAvatarSquare", ViewData["PostAvatarSquare"])
                    </div>
                </div>
                <br />
                <img id="imgAvatarYanNews" src="@Url.Content("http://s1.img.yan.vn/Mlog/UploadThumbs/" + folder + "/300x150_" + ViewData["PostAvatarYanNews"])" alt=""/>
                <br />
                <div>
                    <div style="float: left; margin-top: 10px; margin-right: 17px;">
                        <b>@Html.Raw("Hình YanNews")</b>
                    </div>
                    <div id="dvUploadAvatarYanNews">
                        @Html.Hidden("PostAvatarYanNews", ViewData["PostAvatarYanNews"])
                    </div>
                </div>
                <br />
            }
            else
            { 
                @Html.Hidden("PostAvatarFeature")
                @Html.Hidden("PostAvatarSquare")
                @Html.Hidden("PostAvatarYanNews")
            }
            <img id="imgAvatar" src="@Url.Content("http://s1.img.yan.vn/Mlog/UploadThumbs/" + folder + "/196x196_" + ViewData["PostAvatar"])" alt=""/>
            @Html.Hidden("FolderImage", ViewData["Folder"])
            <br />
            <div>
                <div style="float: left; margin-top: 10px; margin-right: 26px;">
                    <b>@Html.Raw("Hình đại diện")</b>
                </div>
                <div id="dvUpload">
                    @Html.Hidden("PostAvatar", ViewData["PostAvatar"])
                </div>
            </div>
            @if (Roles.IsUserInRole("SuperAdmin") || Roles.IsUserInRole("Admin"))
            {
                <br />
                <div>
                    <div style="float: left; margin-top: 10px; margin-right: 26px;">
                        <b>@Html.Raw("Video Id")</b>
                    </div>
                    <div>
                        @Html.TextBox("VideoUrl", ViewData["VideoUrl"])
                    </div>
                </div>
            }
            else
            {
                @Html.Hidden("VideoUrl");
            }
            <br />
            <br />
            @if (Roles.IsUserInRole("SuperAdmin"))
            {
                <b>Lượt thích</b><br />
                @Html.TextBoxFor(model => model.Post.LikeCount)
                <br />
                <br />
                <br />
                <b>Lượt hiển thị</b><br />
                @Html.TextBoxFor(model => model.Post.ViewCount)
                <br />
                <br />
            }
            else
            { 
                @Html.HiddenFor(model => model.Post.LikeCount)
                @Html.HiddenFor(model => model.Post.ViewCount)
            }
            @Html.TextAreaFor(model => model.Post.PostContent)
            <br />
            <b>Url</b>
            <br />
            <br />
            <h4 class="postUrlLabel" title="click to edit the url">
                ---</h4>
            <span class="postUrlPrefix"></span>@Html.TextBoxFor(model => model.Post.PostUrl, new { @class = "postUrl" })
            @Html.HiddenFor(model => model.Post.PostUrl, new { @class = "postUrlValue" })
            <span class="urlControls">
                <input type="button" id="btnUpdate" value="ok" />&nbsp;<input type="button" id="btnCancel"
                    value="cancel" />
            </span>
            @if (Roles.IsUserInRole("SuperAdmin") || Roles.IsUserInRole("Admin"))
            {
                <div style="position: absolute; top: 1200px; left: 70px;">
                    <b>Chèn hình</b>
                    <br />
                    <div id="divContentUploader">
                    </div>
                </div>
            }
            else
            { 
                <div style="position: absolute; top: 700px; left: 70px;">
                    <b>Chèn hình</b>
                    <br />
                    <div id="divContentUploader">
                    </div>
                </div>    
            }
        </div>
        <div id="right" style="float: left;">
            <div class="cpHeader">
                <b>Lựa chọn xuất bản</b>
            </div>
            <div class="cpContent">
                @if (Roles.IsUserInRole("SuperAdmin") || Roles.IsUserInRole("Admin"))
                {
                    @Html.CheckBoxFor(model => model.Post.IsPrivate, new { @class = "privateChkBox" })
                    @Html.Raw("Ẩn tin này")
                    <br />
                    <br />
                    @Html.CheckBoxFor(model => model.Post.Promote)
                    @Html.Raw("Bài độc quyền")
                    <br />
                    <br />
                    <b>Vị trí hiển thị</b><br />
                    @Html.TextBoxFor(model => model.Post.OrderNumber)
                    <br />
                    <br />
                    <b>Loại promote</b><br />
                    @Html.TextBoxFor(model => model.Post.PromoteType)
                    <br />
                    <br />
                }
                else
                {   
                    @Html.HiddenFor(model => model.Post.Promote)
                    @Html.HiddenFor(model => model.Post.OrderNumber)
                    @Html.HiddenFor(model => model.Post.PromoteType)
                    @Html.HiddenFor(model => model.Post.IsPrivate)
                }
                <input type="submit" value="Publish" class="publishBtn" onclick="return ValidForm();" />
                <span>&nbsp;</span>
                @if (Model.Post.EntryType == 1)
                {
                    @Html.ActionLink("delete post", "DeletePost", "Post", new { postID = Model.Post.PostID }, new { @class = "edit-trash" });
                }
                else
                {
                    @Html.ActionLink("delete page", "DeletePage", "Page", new { postID = Model.Post.PostID }, new { @class = "edit-trash" });
                }
            </div>
            <br />
            <br />
            @if (Roles.IsUserInRole("SuperAdmin") || Roles.IsUserInRole("Admin"))
            {
                <div class="cpHeader">
                    <b>Lựa chọn hiển thị</b>
                </div>
                <div class="cpContent">
                    @Html.CheckBoxFor(model => model.Post.IsHome)
                    @Html.Raw("Tiêu điểm trong ngày")
                    <br />
                    <br />
                    @Html.CheckBoxFor(model => model.Post.IsCatHome)
                    @Html.Raw("Set tin trang chủ chuyên mục")
                    <br />
                    <br />
                    @Html.CheckBoxFor(model => model.Post.IsHomeUser)
                    @Html.Raw("Ngăn kéo")
                    <br />
                    <br />
                    @Html.CheckBoxFor(model => model.Post.IsFeature)
                    @Html.Raw("Set tin tiêu điểm")
                    <br />
                    <br />
                    @Html.CheckBoxFor(model => model.Post.ShowReadPage)
                    @Html.Raw("Set tin trang reading")
                    <br />
                    <br />
                    @Html.CheckBoxFor(model => model.Post.IsYanNews)
                    @Html.Raw("Widget YanNews")
                    <br />
                    <br />
                    &nbsp;&nbsp;@Html.Raw("MChoice")
                    <br />
                    &nbsp;&nbsp;@Html.DropDownList("Post.MChoice", (List<SelectListItem>)ViewBag.lstMChoice, new { style = "width: 150px" })
                </div>
                @Html.HiddenFor(model => model.Post.UserCanAddComments)
                @Html.HiddenFor(model => model.Post.CanBeShared)
            }
            else
            {
                @Html.HiddenFor(model => model.Post.IsHome)
                @Html.HiddenFor(model => model.Post.IsCatHome)
                @Html.HiddenFor(model => model.Post.IsHomeUser)
                @Html.HiddenFor(model => model.Post.IsFeature)
                @Html.HiddenFor(model => model.Post.ShowReadPage)
                @Html.HiddenFor(model => model.Post.UserCanAddComments)
                @Html.HiddenFor(model => model.Post.CanBeShared)
                @Html.HiddenFor(model => model.Post.IsYanNews)
            }
            @if (Model.Post.EntryType == 1)
            {
                <div class="cpHeader">
                    <b>Chọn danh mục</b>
                </div>
                <div class="cpContent">
                    @Html.Partial("Categories", Model.Categories)
                </div>
            }
            @if (Model.Post.EntryType == 2)
            {
                
                <div class="cpHeader">
                    <b>Page Order</b>
                </div>
                <div class="cpContent">
                    @Html.TextBoxFor(model => model.Post.Order, new { @class = "inputBoxBigOrder" })
                </div>
            }
            @Html.HiddenFor(model => model.Post.EntryType)
            @if (Model.Post.EntryType == 1)
            {
                <br />
                <div class="cpHeader">
                    <b>Tags</b>
                </div>
                <div class="cpContent">
                    @Html.Partial("Tags", Model.Tags)
                </div>
            }
            @if (Roles.IsUserInRole("SuperAdmin") || Roles.IsUserInRole("Admin"))
            {
                <br />
                <b>Ngày xuất bản</b>
                <br />
                @Html.TextBoxFor(model => model.Post.PublicDate, new { id = "PublicDate" })
                <br />
                <br />
                <b>Giờ</b><br />                
                @Html.TextBox("txtHour", ViewData["Hour"])
                <br />
                <br />
                <b>Phút</b><br />                
                @Html.TextBox("txtMinute", ViewData["Minute"])
            }
            else
            { 
                @Html.HiddenFor(model => model.Post.PublicDate) 
            }
        </div>
    </div>
}
